//
// Created by Jingle Wang.
//

#include "../include/common.h"
//#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <chrono>
#define N 10000
#define MASTER "192.168.50.10"



TEST(CoordinatorTest, serialization_Latency_Test){
    std::vector<serializeBuff *> data(N, NULL);
    prepare_latency_data_no_conflict(data, N, 10);
}



TEST(CoordinatorTest,Latency_test){

     rdma_fd *handler = (rdma_fd *)malloc(sizeof(rdma_fd));
     int ret = build_connection(handler, MASTER, MASTER_PORT);
     ASSERT_EQ(ret, 0);
     std::vector<serializeBuff *> data(N, NULL);
     prepare_latency_data_no_conflict(data, N, 10);
   //time begin;
     auto start = std::chrono::system_clock::now();
     for(int i = 0; i < N; i++){
         client_send_message(handler, data[i], PROPOSE);
         wait_replies_for_latency_test(handler);
     }
     auto end = std::chrono::system_clock::now();
     std::chrono::duration<double> diff = end-start;
     printf("[TIME]: %lf [Latency]: %lf us\n", diff.count(), (double) diff.count() * 1000000 / N);
// //  time end;    
}





int main(int argc, char * argv[]) {
    testing::InitGoogleTest(&argc, argv);  
    return RUN_ALL_TESTS();  
}



